<template>
  <div>
    <el-button v-if="device.message.Voltage > 0.15" icon="el-icon-switch-button"
      @click="onOperate('OFF',device.devMac)"> {{ $t('Off') }}</el-button>
    <el-button v-else icon="el-icon-switch-button" @click="onOperate('ON',device.devMac)"> {{ $t('On') }} </el-button>
    <el-form v-if="device.code">
      <el-form-item :label="$t('device.Voltage')">{{ device.message.Voltage }} (V)</el-form-item>
      <el-form-item :label="$t('device.Current')">{{ (device.message.Current/1000).toFixed(3) }} (A)</el-form-item>
    </el-form>
    <!-- <el-row v-if="device.code">
          <el-col :span="8">
          </el-col>
          </el-row>
          <el-alert v-else title="请等待模块响应" :closable="false" type="info"></el-alert> -->
  </div>
</template>
<script>
  import Common from './common'
  export default {
    name: "Screen",
    mixins: [Common],
    methods: {
      onOperate(command, DevMac) {
        const content = {
          PackageType: 0,
          DeviceControl: {
            DevMac,
            Message: {}
          }
        }
        if (command === 'ON') {
          content.DeviceControl.Message = {
            "IrSend": {
              "Mode": 0,
              "Order": 1,
              "Temp": 0
            }
          }
          this.deviceCommand("control", JSON.stringify(content))
          content.DeviceControl.Message = {
            "CodeSend": 1
          }
          this.deviceCommand("control", JSON.stringify(content))
        } else if (command === 'OFF') {
          content.DeviceControl.Message = {
            "IrSend": {
              "Mode": 0,
              "Order": 0,
              "Temp": 0
            }
          }
          this.deviceCommand("control", JSON.stringify(content))
          content.DeviceControl.Message = {
            "CodeSend": 2
          }
          this.deviceCommand("control", JSON.stringify(content))
        }
      }
    }
  }

</script>
